﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace AccountsPayable
{
    public class Company : TaxEntity
    {
        String name;
        LinkedList<TaxEntity> employees;

        public Company(String name, String taxId) 
            : base(taxId)
        {
            Name = name;
            employees = new LinkedList<TaxEntity>();
        }

     #region Properties
        public String Name
        {
            get { return name; }
            set 
            {
                if (value != null && Regex.IsMatch(value, @"^[A-Za-z\-\'\s\$\!]{1,30}$"))
                {
                    name = value;
                }
                else
                {
                    throw new ArgumentException();
                }
  
            }
        }

        protected override string TaxIdRegex
        {
            get { return @"^\d\d-\d{7}$"; }
        }


        public IEnumerable<TaxEntity> Employees
        {
            get { return employees; }
        }

        #endregion

        public void hire(TaxEntity newhire)
        {
            if (newhire != null)
                employees.AddLast(newhire);
            else
                throw new ArgumentNullException();
        }

        public override float Pay()
        {
            float totalNet = 0;
            foreach (TaxEntity e in employees)
            {
                totalNet += e.Pay();
            }
            return totalNet;
        }
    }
}
